/*
 * CSelectUtils.h
 *
 *  Created on: 2011-9-10
 *      Author: stargui
 */

#ifndef CSELECTUTILS_H_
#define CSELECTUTILS_H_

#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
namespace Common
{
typedef enum
{
	FD_SETS_READ = 0,

	FD_SETS_WRITE = 1,

	FD_SETS_ERROR = 2,

	FD_SETS_COUNT = 3,

} FD_SETS_ENUMS;

class CSelectUtils
{
private:

	int _maxhandle;

	fd_set _sets[FD_SETS_COUNT];

public:

	CSelectUtils();

	virtual ~CSelectUtils();

public:

	int InsertfdSets(int fd, FD_SETS_ENUMS sets);

	int Select(int timeout = 0);

	int Select(struct timeval &remainder, int timeout = 0);

	bool CheckSets(int fd, FD_SETS_ENUMS sets);
};
}
#endif /* CSELECTUTILS_H_ */
